<!--医师-->
<template slot-scope="props">
	<section>
		<el-form :inline="true" :model="formInline" class="demo-form-inline" size="medium">
			<el-form-item label="医师姓名">
				<el-autocomplete class="inline-input" @input="queryAll()" v-model="formInline.dmmc" :fetch-suggestions="querySearch"
				 placeholder="请输入内容" @select="handleSelect"></el-autocomplete>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="queryAll()">新增</el-button>
			</el-form-item>

			<el-table :data="tableData" border  height="400px">
				<el-table-column prop="dm" label="代码">
					<template slot-scope="scope">
						<el-input v-model="scope.row.dm" placeholder="请输入" ></el-input>
					</template>
				</el-table-column>
				<el-table-column prop="ksdm" label="科室代码">
					<template slot-scope="scope">
						<el-input v-model.trim="scope.row.ksdm" placeholder="请输入" @keyup.32.native="eee(scope.$index,scope.row.date)"></el-input>
					</template>
				</el-table-column>
				<el-table-column prop="ksmc" label="科室名称" >
					
				</el-table-column>
				<el-table-column prop="dmmc" label="医师姓名">
					<template slot-scope="scope">
						<el-input v-model="scope.row.dmmc" placeholder="请输入" ></el-input>
					</template>
				</el-table-column>
				<el-table-column prop="yszc" label="医师职称" :formatter="yszcFormat">
					<template slot-scope="scope">
						<el-select v-model="scope.row.yszc" placeholder="请选择" >
							<el-option v-for="item in yszcOptions" :key="item.yszcvalue" :label="item.yszclabel" :value="item.yszcvalue">
							</el-option>
						</el-select>
					</template>
				</el-table-column>
				<el-table-column prop="ysbz" label="医师类别" :formatter="ysbzFormat">
					<template slot-scope="scope">
						<el-select v-model="scope.row.ysbz" placeholder="请选择" >
							<el-option v-for="item in ysbzOptions" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-select>
					</template>
				</el-table-column>
				<el-table-column prop="bz" label="是否停用">
					<template slot-scope="scope">
						<el-switch v-model="scope.row.bz" active-value="1" inactive-value="0" active-text="启" inactive-text="停"
						 active-color="#13ce66" inactive-color="#ff4949" >
						</el-switch>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="180">
					<template slot-scope="scope">
						 <el-button size="mini" @click="update(scope.row)">修改</el-button> 
						<el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-form>

		<paging-toolbar :pager="pager" @change="queryAll('condition')" />
		<template>
			<department-dictionary :show.sync="show" ref="dialogtree" :msg.sync="indexs"></department-dictionary>
		</template>
	</section>
</template>

<script>
	import {
		GetDoctorDictionary,
		UpdategetDoctorDictionary
	} from "@/api";
	import departmentDictionary from '../../components/dialog/departmentdictionary'
	import PagingToolbar from '../../components/toolbar/paging';
	export default {
		components: {
			PagingToolbar,
			'department-dictionary': departmentDictionary
		},
		data() {
			return {
				show: false,
				indexs: 0,
				pager: {
					total: 0, // 总条数
					page: 1, // 当前页
					rows: 10 // 每页显示多少条
				},
				restaurants: [],
				formInline: {
					user: '',
					region: ''
				},
				tableData: [],
				ysbzOptions: [{
						value: '1',
						label: '门诊医师'
					},
					{
						value: '2',
						label: '住院医师'
					}
				],
				value: '',
				yszcOptions: [{
						yszcvalue: '1',
						yszclabel: '正副主任医师'
					}, {
						yszcvalue: '2',
						yszclabel: '主治医师'
					},
					{
						yszcvalue: '3',
						yszclabel: '医师医士'
					},
					{
						yszcvalue: '4',
						yszclabel: '进修实习人员'
					}
				],
				yszcvalue: ''
			}
		},
		methods: {
			eee(index, res) {
				this.indexs = index
				this.show = true;
			},
			bbb() {
				this.$refs.dialogtree.dialogOpen();
			},

			querySearch(queryString, cb) {
				var restaurants = this.restaurants;
				var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
				// 调用 callback 返回建议列表的数据
				cb(results);
			},
			createFilter(queryString) {
				return (restaurant) => {
					return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
				};
			},
			queryAll(condition) {
				
				let formInitData = {}
				if (condition === undefined) { // 条件查询
					sessionStorage.setItem('formInit', JSON.stringify(this.formInline))
					this.formInline.page = 1
					this.formInline.limit = this.pager.rows
					formInitData = this.formInline
				} else { // 分页查询
					let formInit = JSON.parse(sessionStorage.getItem('formInit'))
					if (JSON.stringify(formInit) !== '{}') {
						formInitData = formInit
					}
					formInitData.page = this.pager.page
					formInitData.limit = this.pager.rows
				}
				// 请求数据
				GetDoctorDictionary(formInitData).then(res => {
					this.pager.page = formInitData.page
					this.pager.total = res.data.data.total
					this.tableData = res.data.data.content
				})
			},

			yszcFormat(row, column) {

				if (row.yszc === "1") {
					return '正副主任医师'
				} else if (row.yszc === "2") {
					return '主治医师'
				} else if (row.yszc === "3") {
					return '医师医士'
				} else if (row.yszc === "4") {
					return '进修实习人员'
				}
			},

			ysbzFormat(row, column) {
				if (row.ysbz === "1") {
					return '门诊医师'
				} else if (row.ysbz === "2") {
					return '住院医师'
				}
			},
			loadAll() {
				return [
				];
			},
			handleSelect(item) {
				console.log(item);
			},
			fatherMethod(res, index) {
				this.tableData[index].ksdm = res.dm
				this.tableData[index].ksmc = res.dmmc
				this.show = false;
			},
			handleDelete(row) {
				this.$confirm('此操作将永久删除此人员, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {

					this.$message({
						type: 'success',
						message: '删除成功!'
					});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});
			},
			update(row) {
			
				this.$confirm('确定要修改此项吗, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					UpdategetDoctorDictionary(row).then(res =>{
						if (res.data.code === 0) {
							this.$message({
								type: 'success',
								message: '修改成功!'
							});
						}else{
							this.$message({
								type: 'error',
								message: '修改失败请联系管理员!'
							});
						}
						this.queryAll();
					})
				
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消修改'
					});
					this.queryAll();
				});

			}

		},
		mounted() {
			this.restaurants = this.loadAll();
			this.queryAll();
		}
	};
</script>

<style>
	.el-select .el-input {
		width: 130px;
	}

	.input-with-select .el-input-group__prepend {
		background-color: #fff;
	}

	.el-dropdown-link {
		cursor: pointer;

	}

	.el-icon-arrow-down {
		font-size: 12px;
	}
</style>
